#include "../tree/DtdTree.h"

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;


int main( )
{
	DtdTree tree;

	/* <!ELEMENT A EMPTY > */
	DtdDeclaration decA;
	decA.name = "A";
	decA.elementType = EMPTY;
	decA.tree = NULL;

	std::string attr = "id";

	decA.addAttribut(attr);
	attr = "ref";
	decA.addAttribut(attr);
	attr = "date";
	decA.addAttribut(attr);

	/* <!ELEMENT B (#PCDATA) > */
	DtdDeclaration decB;
	decB.name = "B";
	decB.elementType = PCDATA;
	decB.tree = NULL;

	/* <!ELEMENT C ANY > */
	DtdDeclaration decC;
	decC.name = "C";
	decC.elementType = ANY;
	decC.tree = NULL;

	/* <!ELEMENT D (A)+ > */
	DtdElement elmA;
	elmA.card = ONE;
	elmA.name = "A";

	DtdComposite dComp;
	dComp.card = ONE_PLUS;
	dComp.compositeType = CHC;
	dComp.appendChild(&elmA);

	DtdDeclaration decD;
	decD.name = "D";
	decD.elementType = CHILDREN;
	decD.tree = &dComp;

	/* <!ELEMENT F (A,B,C(D|E)) > */
	DtdDeclaration decE;
	decE.name = "E";
	decE.elementType = ANY;
	decE.tree = NULL;

	DtdElement elmA2;
	elmA2.card = ONE;
	elmA2.name = "A";

	DtdElement elmB;
	elmB.card = ONE_PLUS;
	elmB.name = "B";

	DtdElement elmC;
	elmC.card = ZERO_ONE;
	elmC.name = "C";

	DtdElement elmD;
	elmD.card = ONE;
	elmD.name = "D";

	DtdElement elmE;
	elmE.card = ONE;
	elmE.name = "E";

	DtdComposite compDE;
	compDE.card = ONE_PLUS;
	compDE.compositeType = CHC;
	compDE.appendChild(&elmD);
	compDE.appendChild(&elmE);

	DtdComposite compABC;
	compABC.card = ZERO_PLUS;
	compABC.compositeType = SEQ;
	compABC.appendChild(&elmA2);
	compABC.appendChild(&elmB);
	compABC.appendChild(&elmC);
	compABC.appendChild(&compDE);

	DtdDeclaration decF;
	decF.name = "F";
	decF.elementType = CHILDREN;
	decF.tree = &compABC;

	/* <!ELEMENT G (#PCDATA|A|B)* > */
	DtdElement elmA3;
	elmA3.card = ONE;
	elmA3.name = "A";

	DtdElement elmB3;
	elmB3.card = ONE;
	elmB3.name = "B";

	DtdComposite compG;
	compG.card = ZERO_PLUS;
	compG.compositeType = CHC;
	compG.appendChild(&elmA3);
	compG.appendChild(&elmB3);

	DtdDeclaration decG;
	decG.name = "G";
	decG.elementType = PCDATA;
	decG.tree = &compG;

	tree.addDeclaration(&decA);
	tree.addDeclaration(&decB);
	tree.addDeclaration(&decC);
	tree.addDeclaration(&decD);
	tree.addDeclaration(&decE);
	tree.addDeclaration(&decF);
	tree.addDeclaration(&decG);

	cout << tree.buildTreeStructure() << endl;
	cout << tree.getDtdAsString() << endl;

	cout << endl << "------ REGEX TEST --------" << endl << endl;

	regex rgx;
	string rgxStr, tstStr;
	bool result;
	tree.getDtdRegex("F", rgxStr);
	rgx = rgxStr;
	tstStr = "A;B;B;B;C;D;D;E;D;E;E;";
	result = regex_match(tstStr, rgx);
	cout << "F REGEX EXPR : " << rgxStr << endl;
	cout << "ON TESTE F AVEC : " << tstStr << " : attendu : 1 res = " << result << endl;


	return 0;
}